/*************************************************************************
 Copyright (C) Unpublished Unis Software, Inc. All rights reserved.
 Unis Software, Inc., Confidential and Proprietary.

 This software is subject to copyright protection
 under the laws of the Public of China and other countries.

 Unless otherwise explicitly stated, this software is provided
 by Unis "AS IS".
 *************************************************************************/
package com.unis.service.board;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.unis.common.util.TemplateUtil;
import com.unis.dao.IDataSet4iBatis;
import com.unis.model.BaseModel;
import com.unis.model.board.BoardRoom;

/**
 * @author Alucard (email:357375084@qq.com)
 * @since 2013-03-14
 */
@Service("boardroomService")
public class BoardRoomServiceImpl implements BoardRoomService {

    private IDataSet4iBatis iDataSet4iBatis;    

    /****************************************
     * Insert a instace of BoardRoom
     ****************************************/
    public void insert(BoardRoom boardroom) throws Exception {
        boardroom.setRoomid(TemplateUtil.genUUID());
        iDataSet4iBatis.insert(boardroom);
    }

    /****************************************
     * Update a instace of BoardRoom
     ****************************************/
    public void update(BoardRoom boardroom) throws Exception {
        iDataSet4iBatis.update(boardroom);
    }

    /****************************************
     * Delete a instace of BoardRoom
     ****************************************/
    public void delete(BoardRoom boardroom) throws Exception {
        iDataSet4iBatis.delete(boardroom);
    }

    /****************************************
     * Insert instaces of SysUser
     ****************************************/
    public void batchInsert(BoardRoom boardroom) throws Exception {
        throw new RuntimeException("Not yet implement!");
    }

    /****************************************
     * Delete instaces of SysUser
     ****************************************/
    public void batchDelete(BoardRoom boardroom) throws Exception {
        String statementId = boardroom.getStatmentId();
        String mainId = boardroom.getId();
        String[] ids = mainId.split(",");
        List<BaseModel> boardroomList = new ArrayList<BaseModel>();
        for (String id : ids) {
            BoardRoom model = new BoardRoom();
            model.setStatmentId(statementId);
            model.setId(id.trim());
            boardroomList.add(model);
        }
        iDataSet4iBatis.batchDelete(boardroomList);
    }

    /****************************************
     * Query instaces of BoardRoom
     ****************************************/
    public List<BaseModel> queryAsList(BoardRoom boardroom) throws Exception {
        String queryListStatement = "";
        if (boardroom.isPaging()) {
            queryListStatement = boardroom.getStatmentId();
            boardroom.setStatmentId("BoardRoom.queryRecordsCount");
            BaseModel baseModel = iDataSet4iBatis.queryAsObject(boardroom);
            boardroom.setTotalCount(baseModel.getTotalCount());
            boardroom.setStatmentId(queryListStatement);
        }
        return iDataSet4iBatis.queryAsList(boardroom);
    }

    /****************************************
     * Query a instaces of BoardRoom
     ****************************************/
    public BaseModel queryAsObject(BoardRoom boardroom) throws Exception {
        return iDataSet4iBatis.queryAsObject(boardroom);
    }

    @Resource
    public void setiDataSet4iBatis(IDataSet4iBatis iDataSet4iBatis) {
        this.iDataSet4iBatis = iDataSet4iBatis;
    } 
}
